import { message, Modal, notification } from 'antd';

export class UI {

    static info(content: string, duration: number = 5) {
        message.info(content, duration, undefined)
    }

    static warning(content: string, duration: number = 5) {
        message.warning(content, duration, undefined)
    }

    static success(content: string, duration: number = 5) {
        message.success(content, duration, undefined)
    }

    static error(content: string, duration: number = 5) {
        message.error(content, duration, undefined)
    }

    static errorNotification(content: string, title: string = "错误", duration: number = 5) {
        notification.error({
            closeIcon: true,
            message: title,
            description: content,
            duration
        })
    }

    static confirm(content: string, title: string = "", okText: string = "确定", cancelText: string = "取消"): Promise<boolean> {
        return new Promise(resolve => {
            Modal.confirm({
                title: title,
                content: content,
                okText,
                cancelText,
                onOk: () => resolve(true),
                onCancel: () => resolve(false)
            })
        })
    }

}